home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / psgml / iso-sgml.el.z / iso-sgml.el
Encoding:
Text File  |  1998-05-21  |  7.8 KB  |  262 lines

  1. ;; iso-sgml.el --- display SGML entity references as ISO 8859-1 characters
  2.  
  3. ;; Copyright (C) 1994 Frederic Lepied
  4.  
  5. ;; Author: Frederic Lepied <lepied@cenaath.cena.dgac.fr>
  6. ;; Maintainer: lepied@cenaath.cena.dgac.fr
  7. ;; Keywords: SGML, HTML, ISO, Latin, i18n
  8. ;; Status: Works with emacs 19.24
  9. ;; Created: 1994-06-21
  10. ;; Last Modified By: Frederic Lepied [STERIA SIT] 69577103
  11. ;; Last Modified On: Wed Dec  7 10:14:41 1994
  12. ;; Update Count: 5
  13.  
  14. ;; LCD Archive Entry:
  15. ;; iso-sgml|Frederic Lepied|lepied@cenaath.cena.dgac.fr|
  16. ;; Edit SGML or HTML buffers with ISO 8859-1 (Latin-1) display|
  17. ;; 10-May-1995|1.4|~/misc/iso-sgml.el.Z|
  18.  
  19. ;; $Id: iso-sgml.el,v 1.3 1994/12/07 09:08:07 lepied Exp lepied $
  20.  
  21. ;; This program is free software; you can redistribute it and/or modify
  22. ;; it under the terms of the GNU General Public License as published by
  23. ;; the Free Software Foundation; either version 2, or (at your option)
  24. ;; any later version.
  25. ;;
  26. ;; This program is distributed in the hope that it will be useful,
  27. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29. ;; GNU General Public License for more details.
  30. ;;
  31. ;; You should have received a copy of the GNU General Public License
  32. ;; along with this program; if not, you can either send email to this
  33. ;; program's maintainer or write to: The Free Software Foundation,
  34. ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
  35.  
  36. ;; Commentary:
  37. ;; Based on iso-cvt.el from Michael Gschwind <mike@vlsivie.tuwien.ac.at>,
  38. ;; iso-sgml.el transparently displays entity references in SGML or HTML
  39. ;; buffers as ISO 8859-1 (aka Latin-1) characters.
  40. ;; Modified for XEmacs 19.15 to include the proposed extensions to Latin-1
  41. ;;  by Steve Baur <steve@altair.xemacs.org>
  42.  
  43. ;; SEE ALSO:
  44. ;; iso-cvt.el
  45. ;; If you are interested in questions related to using the ISO 8859-1 
  46. ;; characters set (configuring emacs, Unix, etc. to use ISO), then you
  47. ;; can get the ISO 8859-1 FAQ via anonymous ftp from 
  48. ;; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
  49.  
  50. ;; INSTALLATION:
  51. ;; add the following line to your .emacs :
  52. ;; (load "iso-sgml")
  53. ;; If you want it to work with other modes change the value of the
  54. ;; the variable isosgml-modes-list like this :
  55. ;; (setq isosgml-modes-list '(my-mode))
  56.  
  57. ;; Code:
  58.  
  59. (defconst isosgml-version "$Id: iso-sgml.el,v 1.3 1994/12/07 09:08:07 lepied Exp lepied $"
  60.   "iso-sgml RCS version number")
  61.  
  62. (defvar isosgml-modes-list '(html-mode html-helper-mode sgml-mode)
  63.   "*List of modes to translate between SGML or HTML entity references
  64.  and the ISO 8859-1 character set.")
  65.  
  66.  
  67. (defun isosgml-translate-conventions (trans-tab)
  68.   "Use the translation table argument to translate the current buffer."
  69.   (save-excursion
  70.     (let ((beg (point-min-marker))    ; see the `(elisp)Narrowing' Info node
  71.       (end (point-max-marker)))
  72.       (unwind-protect
  73.       (progn
  74.         (widen)
  75.         (goto-char (point-min))
  76.         (let ((buffer-read-only nil) ; (inhibit-read-only t)?
  77.           (case-fold-search nil))
  78.           (while trans-tab
  79.         (save-excursion
  80.           (let ((trans-this (car trans-tab)))
  81.             (while (search-forward (car trans-this) nil t)
  82.               (replace-match (car (cdr trans-this)) t t)))
  83.           (setq trans-tab (cdr trans-tab))))))
  84.     (narrow-to-region beg end)))))
  85.  
  86. (defvar sgml2iso-trans-tab
  87.   '(
  88.     ("Æ\;"  "╞")
  89.     ("Á\;"  "┴")
  90.     ("Â\;"  "┬")
  91.     ("À\;"  "└")
  92.     ("Ã\;"  "├")
  93.     ("Ç\;"  "╟")
  94.     ("É\;"  "╔")
  95.     ("È\;"  "╚")
  96.     ("Ë\;"  "╦")
  97.     ("Í\;"  "═")
  98.     ("Î\;"  "╬")
  99.     ("Ì\;"  "╠")
  100.     ("Ï\;"  "╧")
  101.     ("Ñ\;"  "╤")
  102.     ("Ó\;"  "╙")
  103.     ("Ô\;"  "╘")
  104.     ("Ò\;"  "╥")
  105.     ("Ø\;"  "╪")
  106.     ("Ú\;"  "┌")
  107.     ("Ù\;"  "┘")
  108.     ("Ý\;"  "▌")
  109.     ("á\;"  "ß")
  110.     ("â\;"  "Γ")
  111.     ("´\;" "┤")
  112.     ("æ\;"  "µ")
  113.     ("à\;"  "α")
  114.     ("å\;"  "σ")
  115.     ("ã\;"  "π")
  116.     ("¦\;" "ª")
  117.     ("ç\;"  "τ")
  118.     ("¸\;" "╕")
  119.     ("¢\;" "ó")
  120.     ("©\;" "⌐")
  121.     ("¤\;" "ñ")
  122.     ("°\;" "░")
  123.     ("é\;"  "Θ")
  124.     ("ê\;"  "Ω")
  125.     ("è\;"  "Φ")
  126.     ("ë\;"  "δ")
  127.     ("½\;" "╜")
  128.     ("¼\;" "╝")
  129.     ("¾\;" "╛")
  130.     ("í\;"  "φ")
  131.     ("î\;"  "ε")
  132.     ("ì\;"  "∞")
  133.     ("¡\;" "í")
  134.     ("¿\;" "┐")
  135.     ("ï\;"  "∩")
  136.     ("«\;" "½")
  137.     ("¯\;" "»")
  138.     ("µ\;" "╡")
  139.     ("·\;" "╖")
  140.     (" \;" "á")
  141.     ("¬\;" "¼")
  142.     ("ñ\;"  "±")
  143.     ("ó\;"  "≤")
  144.     ("ô\;"  "⌠")
  145.     ("ò\;"  "≥")
  146.     ("ª\;" "¬")
  147.     ("º\;" "║")
  148.     ("ø\;"  "°")
  149.     ("õ\;"  "⌡")
  150.     ("¶\;" "╢")
  151.     ("£\;" "ú")
  152.     ("±\;" "▒")
  153.     ("«\;" "╗")
  154.     ("®\;" "«")
  155.     ("§\;" "º")
  156.     ("­\;" "¡")
  157.     ("¹\;" "╣")
  158.     ("²\;" "▓")
  159.     ("²\;" "│")
  160.     ("ú\;"  "·")
  161.     ("û\;"  "√")
  162.     ("ù\;"  "∙")
  163.     ("¨\;" "¿")
  164.     ("ý\;"  "²")
  165.     ("¥\;" "Ñ")
  166.     ("Ä\;"  "─")
  167.     ("ä\;"  "Σ")
  168.     ("Ö\;"  "╓")
  169.     ("ö\;"  "÷")
  170.     ("Ü\;"  "▄")
  171.     ("ü\;"  "ⁿ")
  172.     ("ß\;"  "▀")
  173.     ("§\;"  "º")
  174.     ("¶\;"  "╢")
  175.     ("©\;"  "⌐")
  176.     ("¡\;"  "í")
  177.     ("¿\;"  "┐")
  178.     ("¢\;"  "ó")
  179.     ("£\;"  "ú")
  180.     ("×\;"  "╫")
  181.     ("±\;"  "▒")
  182.     ("÷\;"  "≈")
  183.     ("¬\;"  "¼")
  184.     ("&mu\;"  "╡")
  185.     ("&Ae\;"  "─")
  186.     ("&ae\;"  "Σ")
  187.     ("&Oe\;"  "╓")
  188.     ("&oe\;"  "÷")
  189.     ("&Ue\;"  "▄")
  190.     ("&ue\;"  "ⁿ")
  191.     ("&sz\;"  "▀")
  192.    )
  193.   "Translation table from SGML entity references to ISO 8859-1 characters.")
  194.  
  195. (defun fix-sgml2iso ()
  196.   "Replace SGML entity references with ISO 8859-1 (aka Latin-1) characters."
  197.   (interactive)
  198.   (if (member major-mode isosgml-modes-list)
  199.       (let ((buffer-modified-p (buffer-modified-p)))
  200.       (unwind-protect
  201.           (isosgml-translate-conventions sgml2iso-trans-tab)
  202.         (set-buffer-modified-p buffer-modified-p)))))
  203.  
  204. (defvar iso2sgml-trans-tab
  205.   (mapcar (function (lambda (entity-char) ; (ENTITY CHAR)
  206.                ;; Return (CHAR ENTITY)
  207.                (list (car (cdr entity-char))
  208.                  (car entity-char))))
  209.        sgml2iso-trans-tab)
  210.    "Translation table from ISO 8859-1 characters to SGML entity references.")
  211.  
  212. (defun fix-iso2sgml ()
  213.   "Replace ISO 8859-1 (aka Latin-1) characters with SGML entity references."
  214.   (interactive)
  215.   (if (member major-mode isosgml-modes-list)
  216.       (let ((buffer-modified-p (buffer-modified-p)))
  217.       (unwind-protect
  218.           (isosgml-translate-conventions iso2sgml-trans-tab)
  219.         (set-buffer-modified-p buffer-modified-p)))))
  220.  
  221.  
  222. (add-hook 'find-file-hooks 'fix-sgml2iso)
  223. (add-hook 'write-file-hooks 'fix-iso2sgml)
  224. (add-hook 'after-save-hook 'fix-sgml2iso)
  225.  
  226. (provide 'iso-sgml)
  227.  
  228. ;; iso-sgml.el ends here
  229.  
  230. ; $Log: iso-sgml.el,v $
  231. ; Revision 1.4  1995/05/10  06:19:41  lepied
  232. ;     * protect code with unwind-protect to prevent errors
  233. ;
  234. ; Revision 1.3  1994/12/07  09:08:07  lepied
  235. ; Thanks to kevinr@ihs.com (Kevin Rodgers)
  236. ;     * replace regular expression search with normal one
  237. ;     * cleanup interactive use
  238. ;
  239. ; Revision 1.2  1994/11/24  06:49:08  lepied
  240. ; Integrated patch from kevinr@ihs.com (Kevin Rodgers) :
  241. ;
  242. ;     * iso-sgml.el (sgml2iso-trans-tab): Delete backslash (`\') from
  243. ;     "±" entity reference.
  244. ;
  245. ;     * iso-sgml.el (file header, library header (Keywords), LCD
  246. ;     Archive Entry (description) [comment blocks]): Properly refer to
  247. ;     SGML entity references; uppercase acronyms (ISO, SGML, HTML);
  248. ;     capitalize Latin.
  249. ;     (Commentary [comment block]): Rewrite as a complete sentence.
  250. ;     (sgml2iso-trans-tab, fix-sgml2iso [doc strings]): Properly refer
  251. ;     to SGML entity references.
  252. ;     (iso2sgml-trans-tab, fix-iso2sgml [doc strings]): Properly refer
  253. ;     to SGML entity references.
  254. ;
  255. ;     * iso-sgml.el (iso2sgml-trans-tab): Initialize by
  256. ;     programmatically reversing elements of sgml2iso-trans-tab,
  257. ;     instead of hand-coding each element.
  258. ;
  259. ; Revision 1.1  1994/06/22  15:15:13  lepied
  260. ; Initial revision
  261. ;
  262.